/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.google.common.base.Objects;
/*     */ import com.google.common.base.Objects.ToStringHelper;
/*     */ import com.zimbra.common.mailbox.Color;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.db.DbMailItem;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Link
/*     */   extends Document
/*     */ {
/*     */   private String mOwnerId;
/*     */   private int mRemoteId;
/*     */   
/*     */   public Link(Mailbox mbox, MailItem.UnderlyingData data)
/*     */     throws ServiceException
/*     */   {
/*  29 */     super(mbox, data);
/*     */   }
/*     */   
/*     */   static Link create(Folder parent, int id, String uuid, String name, String ownerId, int remoteId, MailItem.CustomMetadata custom) throws ServiceException {
/*  33 */     if (!parent.canAccess((short)4)) {
/*  34 */       throw ServiceException.PERM_DENIED("you do not have sufficient permissions on the parent folder");
/*     */     }
/*  36 */     if (!parent.canContain(MailItem.Type.LINK)) {
/*  37 */       throw MailServiceException.CANNOT_CONTAIN();
/*     */     }
/*  39 */     name = validateItemName(name);
/*  40 */     Mailbox mbox = parent.getMailbox();
/*     */     
/*  42 */     MailItem.UnderlyingData data = new MailItem.UnderlyingData();
/*  43 */     data.uuid = uuid;
/*  44 */     data.id = id;
/*  45 */     data.type = MailItem.Type.MOUNTPOINT.toByte();
/*  46 */     data.folderId = parent.getId();
/*  47 */     data.parentId = data.folderId;
/*  48 */     data.date = mbox.getOperationTimestamp();
/*  49 */     data.name = name;
/*  50 */     data.setSubject(name);
/*  51 */     data.metadata = encodeMetadata(DEFAULT_COLOR_RGB, 1, 1, ownerId, remoteId, custom);
/*  52 */     data.contentChanged(mbox);
/*  53 */     ZimbraLog.mailop.info("Adding Link %s: id=%d, parentId=%d, parentName=%s.", new Object[] { name, Integer.valueOf(data.id), Integer.valueOf(parent.getId()), parent.getName() });
/*     */     
/*  55 */     new DbMailItem(mbox).create(data);
/*  56 */     Link link = new Link(mbox, data);
/*  57 */     link.finishCreation(parent);
/*  58 */     return link;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public String getOwnerId()
/*     */   {
/*  65 */     return this.mOwnerId;
/*     */   }
/*     */   
/*     */   public int getRemoteId() {
/*  69 */     return this.mRemoteId;
/*     */   }
/*     */   
/*     */   Metadata encodeMetadata(Metadata meta)
/*     */   {
/*  74 */     return encodeMetadata(meta, this.mRGBColor, this.mMetaVersion, this.mVersion, this.mOwnerId, this.mRemoteId, this.mExtendedData);
/*     */   }
/*     */   
/*     */   private static String encodeMetadata(Color color, int metaVersion, int version, String owner, int remoteId, MailItem.CustomMetadata custom) {
/*  78 */     MailItem.CustomMetadata.CustomMetadataList extended = custom == null ? null : custom.asList();
/*  79 */     return encodeMetadata(new Metadata(), color, metaVersion, version, owner, remoteId, extended).toString();
/*     */   }
/*     */   
/*     */   private static Metadata encodeMetadata(Metadata meta, Color color, int metaVersion, int version, String owner, int remoteId, MailItem.CustomMetadata.CustomMetadataList extended) {
/*  83 */     meta.put("aid", owner);
/*  84 */     meta.put("id", remoteId);
/*  85 */     return encodeMetadata(meta, color, null, metaVersion, version, extended);
/*     */   }
/*     */   
/*     */   void decodeMetadata(Metadata meta) throws ServiceException
/*     */   {
/*  90 */     super.decodeMetadata(meta);
/*  91 */     if (meta == null)
/*  92 */       return;
/*  93 */     this.mOwnerId = meta.get("aid");
/*  94 */     this.mRemoteId = ((int)meta.getLong("id"));
/*     */   }
/*     */   
/*     */   public String toString()
/*     */   {
/*  99 */     Objects.ToStringHelper helper = Objects.toStringHelper(this);
/* 100 */     appendCommonMembers(helper);
/* 101 */     helper.add("type", getType());
/* 102 */     helper.add("owner", this.mOwnerId);
/* 103 */     helper.add("remoteId", this.mRemoteId);
/* 104 */     helper.add("text", getSubject());
/* 105 */     return helper.toString();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/Link.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */